import Shape3D from "./Shape3D";
import Point3D from "../Point/Point3D";
import Surface from "./Surface";

export default class Rect3D extends Shape3D {

    constructor(centre, width, height, length, angle) {
        super(centre, angle);
        this.length = length;
        this.width = width;
        this.height = height;
    }


    getHornPoints() {
        let hornPoints = [];
        let halfWidth = this.width / 2;
        let halfHeight = this.height / 2;
        let halfLength = this.length / 2;
        for (let edge = 1; edge <= 8; edge++) {
            switch (edge) {
                case 1:
                    hornPoints.push(new Point3D(
                        this.centre.x - halfWidth, this.centre.y - halfHeight, this.centre.z - halfLength));
                    break;
                case 2:
                    hornPoints.push(new Point3D(
                        this.centre.x + halfWidth, this.centre.y - halfHeight, this.centre.z - halfLength));
                    break;
                case 3:
                    hornPoints.push(new Point3D(
                        this.centre.x + halfWidth, this.centre.y + halfHeight, this.centre.z - halfLength));
                    break;
                case 4:
                    hornPoints.push(new Point3D(
                        this.centre.x - halfWidth, this.centre.y + halfHeight, this.centre.z - halfLength));
                    break;
                case 5:
                    hornPoints.push(new Point3D(
                        this.centre.x - halfWidth, this.centre.y - halfHeight, this.centre.z + halfLength));
                    break;
                case 6:
                    hornPoints.push(new Point3D(
                        this.centre.x + halfWidth, this.centre.y - halfHeight, this.centre.z + halfLength));
                    break;
                case 7:
                    hornPoints.push(new Point3D(
                        this.centre.x + halfWidth, this.centre.y + halfHeight, this.centre.z + halfLength));
                    break;
                case 8:
                    hornPoints.push(new Point3D(
                        this.centre.x - halfWidth, this.centre.y + halfHeight, this.centre.z + halfLength));
                    break;
                default:
            }
        }
        hornPoints.forEach(point => {
            this.applyDeg(point);
        });
        return hornPoints;
    }

    drawnDataInit() {
        super.drawnDataInit();
        let points = this.getHornPoints();
        this.surfaces.push(new Surface(
            [points[0], points[1], points[2], points[3]], 'top'
        ));
        this.surfaces.push(new Surface(
            [points[4], points[5], points[6], points[7]], 'bottom'
        ));
        this.surfaces.push(new Surface(
            [points[0], points[1], points[5], points[4]], 'behind'
        ));
        this.surfaces.push(new Surface(
            [points[0], points[3], points[7], points[4]], 'left'
        ));
        this.surfaces.push(new Surface(
            [points[2], points[3], points[7], points[6]], 'front'
        ));
        this.surfaces.push(new Surface(
            [points[1], points[2], points[6], points[5]], 'right'
        ));
    }
}